package cn.xiyue.production.base;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import java.util.Objects;

import cn.xiyue.production.ui.TitleBar;

public class BaseActivity extends AppCompatActivity {

    private ProgressDialog progressDialog;
    private Toast toast;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        progressDialog = new ProgressDialog(this);
        progressDialog.setTitle("加载中");

        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            TitleBar titleBar = new TitleBar(this);
            String s = Objects.requireNonNull(actionBar.getTitle()).toString();
            titleBar.setLable(s);
            actionBar.setDisplayShowCustomEnabled(true);
            actionBar.setCustomView(titleBar);
        }

    }

    public void showToast(String msg) {
        if (toast != null) {
            toast.cancel();
        }
        toast = Toast.makeText(this, msg, Toast.LENGTH_SHORT);
        toast.show();
    }


    protected void showDialog() {
        progressDialog.show();
    }

    protected void closeDialog() {
        progressDialog.dismiss();
    }

}
